//
//  DoubleSidedViewController.m
//  CoreAnimation
//
//  Created by 张国文 on 16/10/11.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "DoubleSidedViewController.h"

@interface DoubleSidedViewController ()

@property (nonatomic, strong) UIImageView *peopleImage;
@property (nonatomic, strong) UIView *backgroudView;

@end

@implementation DoubleSidedViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.backgroudView = [[UIView alloc] initWithFrame:self.view.frame];
    self.backgroudView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.5];
    [self.view addSubview:_backgroudView];
    
    self.peopleImage = [[UIImageView alloc] initWithFrame:CGRectMake(100, 50, 150, 150)];
    self.peopleImage.image = [UIImage imageWithName:@"snowMan"];
    self.peopleImage.backgroundColor = [UIColor redColor];
    [self.backgroudView addSubview:_peopleImage];
    
    // 将图层旋转180度，观察反面
    CATransform3D tranform3D = CATransform3DIdentity;
    tranform3D.m34 = - 1.0 / 500.0;
    tranform3D = CATransform3DRotate(tranform3D, M_PI, 0, 1, 0);
    self.peopleImage.layer.transform = tranform3D;
    
    // 观察发现，视图的背面也是绘画了的，我们可以通过doubleSided属性来控制layer背面是否绘制，默认值为YES。当我们不需要看到视图背面的时候可以将这个属性设置为NO，这样会加快GPU的绘制速度，以提高性能。
    self.peopleImage.layer.doubleSided = YES; // 设置为NO以后会发现什么都没有了，界面灰蒙蒙的一片，原因是因为视图背面没有被绘制
    // 因此为了确定视图的位置，我们给视图一个layer的阴影颜色，但是结果发现并没有绘制阴影，原因是doubleSided为NO，背面的所有绘制工作都停止了，阴影也不例外，设置为YES就好了
    self.peopleImage.layer.shadowColor = [UIColor redColor].CGColor;
    self.peopleImage.layer.shadowOffset = CGSizeMake(0, 0);
    self.peopleImage.layer.shadowRadius = 10;
    self.peopleImage.layer.shadowOpacity = 1.0;


}


@end
